package com.qinaxiwit.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qianxi.wit.pojo.TbAdministrator;
import com.qinaxiwit.mapper.TbAdministratorMapper;
import com.qinaxiwit.service.TbAdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyh
 * @since 2021-01-13
 */
@RestController
@RequestMapping("/administrator")
public class TbAdministratorController {

    @Autowired
    private TbAdministratorMapper administratorMapper;
    @Autowired
    private TbAdministratorService administratorService;


    @GetMapping("/aaa")
    public List<TbAdministrator> list(){
        return administratorMapper.selectList(null);

    }
    @PostMapping("/user/administrator")
    public int findUsername(@RequestBody TbAdministrator administrator){

        int i = administratorService.findbyUsername(administrator.getAdministratorUsername(), administrator.getAdministratorPassword());
        if (i>0){
            return 1;
        }else {
            return 0;
        }


    }


    @PutMapping("/{newpassword}/{oldpassword}")
    public int xiu(@RequestBody TbAdministrator administrator,
                   @PathVariable("newpassword")String newpassword,
                   @PathVariable("oldpassword")String oldpassword
                   ){

        System.out.println(administrator.getAdministratorPassword()+"===="+newpassword);
        if (administrator.getAdministratorPassword().equals(newpassword)){
            administrator.setAdministratorPassword(oldpassword);
            administratorMapper.update(administrator,null);
            return 1;
        }
        return 0;

    }



}

